﻿package core.ui.util
{
    import core.enum.*;
    import core.event.*;
    import core.image.*;
    import core.manager.*;
    import core.ui.controls.*;
    import core.ui.dialogs.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.ui.*;

    public class ImageLibraryWindow extends Window
    {
        private var cm:CommandManager;
        private var aslayer:Boolean;
        private var folderlist:Selectbox;
        private var imagelist:ImageBox;
        private var foldermessage:Literal;
        private var imagemessage:Literal;
        private var target:TabBar;
        private var bottombar:Sprite;
        private var grip:Sprite;
        private var cancel:Button;
        private var open:Button;
        private var cmf:ContextMenu;
        private var cmi:ContextMenu;
        private var preview:Bitmap;
        private var pwborder:Sprite;
        private var l1:Sprite;
        private var folderbar:Sprite;
        private var iname:Literal;
        private var itype:Literal;
        private var isize:Literal;
        private var idimensions:Literal;
        private var icreate:Literal;
        private var imodified:Literal;
        private var deleteimage:IconButton;
        private var renameimage:IconButton;
        private var newfolder:IconButton;
        private var renamefolder:IconButton;
        private var deletefolder:IconButton;
        var overlay:Sprite;
        var connect:OpenImageButton;

        public function ImageLibraryWindow(param1:Tuyitu, param2:Boolean = false)
        {
            var ed:*;
            var _arg1:* = param1;
            var _arg2:* = param2;
            ed = _arg1;
            var aslayer:* = _arg2;
            this.aslayer = aslayer;
            super(ed, U.RM("rm_image_library"), false);
            ed.addChild(this);
            ed.SetModal(this, true);
            closeme.addEventListener(MouseEvent.MOUSE_UP, this.CloseClick, false, 0, true);
            this.target = new TabBar();
            this.target.addEventListener(SelectEvent.COMMAND, this.TargetSelect, false, 1, true);
            this.target.AddTab("tuyitu", new TUYITUIcon(), "我的图艺图");
            this.target.AddTab("qqapi", new QQapiIcon(), "QQ相册");
            this.target.AddTab("sina", new TsinaIcon(), "模版与素材中心");
            this.target.x = 4;
            this.target.y = 22;
            addChild(this.target);
            this.folderlist = new Selectbox(200, 200);
            this.folderlist.addEventListener(SelectEvent.COMMAND, this.LoadImageList, false, 1, true);
            this.folderlist.x = 15;
            this.folderlist.y = 60;
            addChild(this.folderlist);
            this.cmf = new ContextMenu();
            this.cmf.hideBuiltInItems();
            this.cmf.addEventListener(ContextMenuEvent.MENU_SELECT, this.FolderContextPrerender, false, 1, true);
            UI.AddToContext(this.cmf, "rm_rename_folder", function (... args)
            {
                new CommandInput(ed, "rm_name", folderlist.item.text, FolderRename);
                return;
            }// end function
            );
            UI.AddToContext(this.cmf, "rm_delete_folder", function (... args)
            {
                new ConfirmDialog(ed, "rm_confirm_delete_folder", FolderDelete);
                return;
            }// end function
            );
            UI.AddToContext(this.cmf, "rm_create_folder", function (... args)
            {
                new CommandInput(ed, "rm_name", "", FolderCreate);
                return;
            }// end function
            , true);
            this.folderlist.contextMenu = this.cmf;
            this.foldermessage = new Literal();
            this.foldermessage.x = 25;
            this.foldermessage.y = 65;
            this.foldermessage.visible = false;
            addChild(this.foldermessage);
            this.imagelist = new ImageBox(200, 200);
            this.imagelist.addEventListener(SelectEvent.COMMAND, this.ImageSelect, false, 1, true);
            this.imagelist.addEventListener(SelectEvent.EXECUTE, this.OpenAndClose, false, 1, true);
            this.imagelist.x = 225;
            this.imagelist.y = 60;
            addChild(this.imagelist);
            this.cmi = new ContextMenu();
            this.cmi.hideBuiltInItems();
            this.cmi.addEventListener(ContextMenuEvent.MENU_SELECT, this.ImageContextPrerender, false, 1, true);
            UI.AddToContext(this.cmi, "rm_open_image", this.OpenAndClose);
            UI.AddToContext(this.cmi, "rm_open_image_and_stay", this.OpenInAndStay);
            UI.AddToContext(this.cmi, "rm_rename_image", function (... args)
            {
                new CommandInput(ed, "rm_name", imagelist.item.details.name, ImageRename);
                return;
            }// end function
            , true);
            UI.AddToContext(this.cmi, "rm_delete_image", function (... args)
            {
                new ConfirmDialog(ed, "rm_confirm_delete_image", ImageDelete);
                return;
            }// end function
            );
            this.imagelist.contextMenu = this.cmi;
            this.imagemessage = new Literal();
            this.imagemessage.x = 235;
            this.imagemessage.y = 65;
            this.imagemessage.visible = false;
            addChild(this.imagemessage);
            this.bottombar = new Sprite();
            this.bottombar.x = 225;
            addChild(this.bottombar);
            this.pwborder = new Sprite();
            this.pwborder.graphics.beginFill(11184810);
            this.pwborder.graphics.drawRect(0, 0, 49, 34);
            this.pwborder.graphics.beginFill(16777215);
            this.pwborder.graphics.drawRect(1, 1, 47, 32);
            this.pwborder.x = 10;
            this.pwborder.y = 10;
            this.bottombar.addChild(this.pwborder);
            this.preview = new Bitmap();
            this.preview.smoothing = true;
            this.preview.width = 45;
            this.preview.height = 30;
            this.preview.x = 2;
            this.preview.y = 2;
            this.pwborder.addChild(this.preview);
            this.iname = new Literal();
            this.iname.x = 65;
            this.iname.y = 9;
            this.bottombar.addChild(this.iname);
            this.itype = new Literal();
            this.itype.x = 65;
            this.itype.y = 25;
            this.bottombar.addChild(this.itype);
            this.l1 = new Sprite();
            this.l1.graphics.beginFill(11184810);
            this.l1.graphics.drawRect(0, 0, 1, 34);
            this.l1.graphics.beginFill(16777215);
            this.l1.graphics.drawRect(1, 0, 1, 34);
            this.l1.graphics.endFill();
            this.l1.y = 10;
            this.bottombar.addChild(this.l1);
            this.idimensions = new Literal();
            this.idimensions.x = 250;
            this.idimensions.y = 9;
            this.bottombar.addChild(this.idimensions);
            this.isize = new Literal();
            this.isize.x = 250;
            this.isize.y = 25;
            this.bottombar.addChild(this.isize);
            this.renameimage = new IconButton(ed, "rm_rename_image", new RenameIcon());
            this.renameimage.addEventListener(MouseEvent.CLICK, function (... args)
            {
                if (imagelist.item != null)
                {
                    new CommandInput(ed, "rm_name", imagelist.item.details.name, ImageRename);
                }
                return;
            }// end function
            , false, 0, true);
            this.renameimage.x = 152;
            this.renameimage.y = 37;
            this.bottombar.addChild(this.renameimage);
            this.deleteimage = new IconButton(ed, "rm_delete_image", new TrashIcon());
            this.deleteimage.addEventListener(MouseEvent.CLICK, function (... args)
            {
                if (folderlist.value != "")
                {
                    new ConfirmDialog(ed, "rm_confirm_delete_image", ImageDelete);
                }
                return;
            }// end function
            , false, 0, true);
            this.deleteimage.x = 176;
            this.deleteimage.y = 37;
            this.bottombar.addChild(this.deleteimage);
            this.folderbar = new Sprite();
            this.folderbar.graphics.beginFill(9474192);
            this.folderbar.graphics.drawRect(0, 0, 200, 23);
            this.folderbar.graphics.beginFill(15395562);
            this.folderbar.graphics.drawRect(1, 1, 198, 21);
            this.folderbar.graphics.endFill();
            this.folderbar.x = 15;
            addChild(this.folderbar);
            this.renamefolder = new IconButton(ed, "rm_rename_folder", new RenameIcon());
            this.renamefolder.addEventListener(MouseEvent.CLICK, function (... args)
            {
                if (folderlist.value != "")
                {
                    new CommandInput(ed, "rm_name", folderlist.item.text, FolderRename);
                }
                return;
            }// end function
            , false, 0, true);
            this.renamefolder.x = 137;
            this.renamefolder.y = 6;
            this.folderbar.addChild(this.renamefolder);
            this.deletefolder = new IconButton(ed, "rm_delete_folder", new TrashIcon());
            this.deletefolder.addEventListener(MouseEvent.CLICK, function (... args)
            {
                if (folderlist.value != "")
                {
                    new ConfirmDialog(ed, "rm_confirm_delete_folder", FolderDelete);
                }
                return;
            }// end function
            , false, 0, true);
            this.deletefolder.x = 159;
            this.deletefolder.y = 6;
            this.folderbar.addChild(this.deletefolder);
            this.newfolder = new IconButton(ed, "rm_create_folder", new NewIcon());
            this.newfolder.addEventListener(MouseEvent.CLICK, function (... args)
            {
                new CommandInput(ed, "rm_name", "", FolderCreate);
                return;
            }// end function
            , false, 0, true);
            this.newfolder.x = 180;
            this.newfolder.y = 6;
            this.folderbar.addChild(this.newfolder);
            this.cancel = new Button("rm_cancel", 70);
            this.cancel.addEventListener(MouseEvent.CLICK, this.CloseClick, false, 0, true);
            addChild(this.cancel);
            this.open = new Button("rm_open", 70);
            this.open.addEventListener(MouseEvent.CLICK, this.OpenAndClose, false, 0, true);
            this.open.visible = false;
            addChild(this.open);
            this.grip = new Sprite();
            this.grip.addChild(new Bitmap(new DragMark()));
            this.grip.addEventListener(MouseEvent.MOUSE_DOWN, this.GripMouseDown, false, 0, true);
            this.grip.addEventListener(MouseEvent.MOUSE_OVER, this.GripMouseOver, false, 0, true);
            this.grip.addEventListener(MouseEvent.MOUSE_OUT, this.GripMouseOut, false, 0, true);
            this.grip.x = 203;
            this.grip.y = 140;
            addChild(this.grip);
            this.Resize(ed.stage.stageWidth > 1000 ? (900) : (ed.stage.stageWidth - 100), ed.stage.stageHeight > 700 ? (600) : (ed.stage.stageHeight - 100));
            this.x = int((ed.stage.stageWidth - this.width) / 2);
            this.y = int((ed.stage.stageHeight - this.height) / 2);
            this.target.Select(AppState.LastLibraryTab, true);
            return;
        }// end function

        override public function Resize(height:int, height:int, height:Boolean = false) : void
        {
            if (height < 550)
            {
                height = 550;
            }
            if (height < 420)
            {
                height = 420;
            }
            super.Resize(height, height, height);
            this.open.x = height - 86;
            this.open.y = height - 44;
            this.cancel.x = height - 86;
            this.cancel.y = height - 68;
            this.folderlist.Resize(200, height - 102);
            this.imagelist.Resize(height - 240, height - 138);
            this.folderbar.y = height - 38;
            this.bottombar.graphics.clear();
            this.bottombar.graphics.beginFill(9474192);
            this.bottombar.graphics.drawRect(0, 0, height - 320, 54);
            this.bottombar.graphics.beginFill(15395562);
            this.bottombar.graphics.drawRect(1, 1, height - 322, 52);
            this.bottombar.graphics.endFill();
            this.bottombar.y = height - 68;
            this.deleteimage.x = height - 341;
            this.renameimage.x = height - 363;
            this.target.Resize(height - 8);
            this.ShowHideInfoOutside();
            if (!height)
            {
                this.grip.x = height - 16;
                this.grip.y = height - 16;
            }
            return;
        }// end function

        public function ShowConnect() : void
        {
            this.overlay = new Sprite();
            this.overlay.graphics.beginFill(12961221);
            this.overlay.graphics.drawRect(4, 50, this.width - 8, this.height - 54);
            addChild(this.overlay);
            this.connect = new OpenImageButton(new UrlImageIcon(), "rm_connect_" + this.target.value, "rm_allow_pop_up", 4);
            this.connect.addEventListener(MouseEvent.CLICK, this.ConnectClick, false, 1, true);
            this.connect.x = int(this.width / 2 - this.connect.width / 2);
            this.connect.y = int(this.height / 2 - this.connect.height / 2);
            addChild(this.connect);
            this.overlay.graphics.beginFill(15724527);
            this.overlay.graphics.drawRect(this.connect.x - 5, this.connect.y - 5, this.connect.width + 10, this.connect.height + 10);
            return;
        }// end function

        public function HideConnect() : void
        {
            if (this.overlay != null)
            {
                removeChild(this.overlay);
                removeChild(this.connect);
                this.overlay = null;
                this.connect = null;
            }
            return;
        }// end function

        public function ConnectClick(... args) : void
        {
            U.Connect(this.target.value, this.ConnectCallBack);
            return;
        }// end function

        public function ConnectCallBack(height:String) : void
        {
            var _loc_2:* = U.JSONResult(height);
            if (_loc_2.success)
            {
                this.LoadFolderList();
            }
            else
            {
                switch(_loc_2.payload.toLowerCase())
                {
                    case "err:popup_block":
                    {
                        new AlertDialog(ed, "rm_allow_pop_up");
                        break;
                    }
                    case "err:not_logged_in":
                    {
                        new LoginDialog(ed, this.LoadImageList, this.Close);
                        break;
                    }
                    default:
                    {
                        new AlertDialog(ed, U.RM("rm_error") + "\n" + _loc_2.payload);
                        break;
                    }
                }
            }
            return;
        }// end function

        public function TargetSelect(... args) : void
        {
            AppState.LastLibraryTab = this.target.value;
            this.imagelist.Clear();
            this.imagemessage.visible = false;
            this.LoadFolderList();
            return;
        }// end function

        public function LoadFolderList(... args) : void
        {
            this.HideConnect();
            this.ClearInfo();
            this.folderlist.Clear();
            this.newfolder.visible = false;
            this.renamefolder.visible = false;
            this.deletefolder.visible = false;
            this.imagemessage.visible = false;
            this.foldermessage.visible = true;
            this.foldermessage.text = U.RM("rm_loading_list");
            U.CallHome(this.target.value + "_folder_list", {service:this.target.value}, this.FolderListCallback);
            return;
        }// end function

        public function FolderListCallback(height:Object) : void
        {
            var _loc_2:int = 0;
            var _loc_3:Object = null;
            var _loc_4:* = new FolderIcon();
            this.foldermessage.visible = false;
            if (height.success)
            {
                if (height.payload.length != 0)
                {
                    _loc_2 = 0;
                    while (_loc_2 < height.payload.length)
                    {
                        
                        _loc_3 = height.payload[_loc_2];
                        this.folderlist.AddItem(_loc_3.name, _loc_3._id, false, _loc_4);
                        _loc_2++;
                    }
                }
                else
                {
                    this.foldermessage.visible = true;
                    this.foldermessage.text = U.RM("rm_no_folders");
                }
                this.newfolder.visible = true;
                this.renamefolder.visible = Boolean(this.target.value == "tuyitu");
                this.deletefolder.visible = Boolean(this.target.value == "tuyitu");
            }
            else
            {
                switch(height.payload.toLowerCase())
                {
                    case "err:no_token":
                    {
                        this.ShowConnect();
                        break;
                    }
                    case "err:not_logged_in":
                    {
                        new LoginDialog(ed, this.LoadFolderList, this.Close);
                        break;
                    }
                    default:
                    {
                        new AlertDialog(ed, U.RM("rm_error") + "\n" + height.payload);
                        break;
                    }
                }
            }
            return;
        }// end function

        public function LoadImageList(... args) : void
        {
            this.ClearInfo();
            this.imagelist.Clear();
            this.imagemessage.visible = true;
            this.imagemessage.text = U.RM("rm_loading_images");
            U.CallHome(this.target.value + "_image_list", {folder_id:this.folderlist.value}, this.ImageListCallback);
            return;
        }// end function

        public function ImageListCallback(height:Object) : void
        {
            var _loc_2:int = 0;
            var _loc_3:Object = null;
            var _loc_4:ImageDetails = null;
            if (height.success)
            {
                if (height.payload.length != 0)
                {
                    this.imagemessage.visible = false;
                    _loc_2 = 0;
                    while (_loc_2 < height.payload.length)
                    {
                        
                        _loc_3 = height.payload[_loc_2];
                        _loc_4 = new ImageDetails(_loc_3._id, _loc_3.name, _loc_3.format, _loc_3.size, _loc_3.width, _loc_3.height, _loc_3.created_at, _loc_3.updated_at, _loc_3.folder_id, this.target.value);
                        this.imagelist.AddItem(_loc_4, _loc_3.thumb_url, _loc_3.full_url);
                        _loc_2++;
                    }
                }
                else
                {
                    this.imagemessage.visible = true;
                    this.imagemessage.text = U.RM("rm_no_images");
                }
            }
            else
            {
                switch(height.payload.toLowerCase())
                {
                    case "err:no_token":
                    {
                        this.ShowConnect();
                        break;
                    }
                    case "err:not_logged_in":
                    {
                        new LoginDialog(ed, this.LoadImageList, this.Close);
                        break;
                    }
                    default:
                    {
                        new AlertDialog(ed, U.RM("rm_error") + "\n" + height.payload);
                        break;
                    }
                }
            }
            return;
        }// end function

        private function FolderContextPrerender(event:ContextMenuEvent) : void
        {
            var _loc_2:SelectItem = null;
            var _loc_3:int = 0;
            while (_loc_3 < this.folderlist.content.numChildren)
            {
                
                _loc_2 = this.folderlist.content.getChildAt(_loc_3) as SelectItem;
                if (_loc_2.hitTestPoint(stage.mouseX, stage.mouseY))
                {
                    break;
                }
                _loc_3++;
            }
            if (_loc_2 != null && _loc_2.name != this.folderlist.value)
            {
                this.folderlist.Set(_loc_2.name);
                this.LoadImageList();
            }
            this.cmf.customItems[0].enabled = Boolean(this.target.value == "tuyitu" && _loc_2 != null);
            this.cmf.customItems[1].enabled = Boolean(this.target.value == "tuyitu" && _loc_2 != null);
            this.cmf.customItems[2].enabled = true;
            return;
        }// end function

        private function ImageContextPrerender(event:ContextMenuEvent) : void
        {
            var _loc_2:ImageInfo = null;
            var _loc_3:int = 0;
            while (_loc_3 < this.imagelist.content.numChildren)
            {
                
                _loc_2 = this.imagelist.content.getChildAt(_loc_3) as ImageInfo;
                if (_loc_2.hitTestPoint(stage.mouseX, stage.mouseY))
                {
                    break;
                }
                _loc_3++;
            }
            if (_loc_2 != null && _loc_2 != this.imagelist.item)
            {
                this.imagelist.Set(_loc_2);
                this.ImageSelect();
            }
            this.cmi.customItems[0].enabled = Boolean(_loc_2 != null);
            this.cmi.customItems[1].enabled = Boolean(_loc_2 != null);
            this.cmi.customItems[2].enabled = Boolean(this.target.value == "tuyitu" && _loc_2 != null);
            this.cmi.customItems[3].enabled = Boolean(this.target.value == "tuyitu" && _loc_2 != null);
            return;
        }// end function

        public function FolderDelete(... args) : void
        {
            U.CallHome(this.target.value + "_folder_delete", {id:this.folderlist.value}, U.TrashBack);
            this.ClearInfo();
            this.imagelist.Clear();
            this.imagemessage.visible = false;
            this.folderlist.RemoveItem();
            this.folderlist.Rearrange();
            if (this.folderlist.content.numChildren == 0)
            {
                this.foldermessage.visible = true;
                this.foldermessage.text = U.RM("rm_no_folders");
            }
            return;
        }// end function

        public function FolderCreate(height:String) : void
        {
            if (height != "")
            {
                U.CallHome(this.target.value + "_folder_create", {name:height}, this.FolderCreateCallback);
            }
            return;
        }// end function

        public function FolderCreateCallback(height:Object) : void
        {
            if (height.success)
            {
                this.folderlist.AddItem(height.payload.name, height.payload._id, true, new FolderIcon());
                this.foldermessage.visible = false;
                this.LoadImageList();
            }
            return;
        }// end function

        public function FolderRename(height:String) : void
        {
            if (height != "" && height != this.folderlist.item.text)
            {
                U.CallHome(this.target.value + "_folder_rename", {id:this.folderlist.value, name:height}, U.TrashBack);
                this.folderlist.item.text = height;
            }
            return;
        }// end function

        public function ImageDelete(... args) : void
        {
            U.CallHome(this.target.value + "_image_delete", {id:this.imagelist.value}, U.TrashBack);
            this.ClearInfo();
            this.imagelist.RemoveItem();
            this.imagelist.Rearrange();
            if (this.imagelist.content.numChildren == 0)
            {
                this.imagemessage.visible = true;
                this.imagemessage.text = U.RM("rm_no_images");
            }
            return;
        }// end function

        public function ImageRename(height:String) : void
        {
            if (height != "" && height != this.imagelist.item.details.name)
            {
                U.CallHome(this.target.value + "_image_rename", {id:this.imagelist.value, name:height}, U.TrashBack);
                this.imagelist.item.details.name = height;
                this.imagelist.item.title = height;
                this.iname.text = height;
            }
            return;
        }// end function

        public function ImageSelect(... args) : void
        {
            args = null;
            if (this.imagelist.item != null)
            {
                args = this.imagelist.item;
                this.pwborder.visible = true;
                this.preview.visible = true;
                this.preview.bitmapData = args.thumb.bitmapData;
                this.preview.width = 45;
                this.preview.height = 30;
                this.iname.text = args.details.name.length > 30 ? (args.details.name.substr(0, 28) + "...") : (args.details.name);
                this.itype.text = args.details.type != "" ? (args.details.type.toUpperCase() + " " + U.RM("rm_image")) : ("");
                this.idimensions.text = args.details.width != 0 && args.details.height != 0 ? (args.details.width + "x" + args.details.height + " px") : ("");
                this.isize.text = args.details.size > 0 ? (Math.round(args.details.size / 1024) + " KB") : ("");
                this.iname.x = this.preview.visible ? (65) : (15);
                this.itype.x = this.preview.visible ? (65) : (15);
                this.l1.x = 5 + this.iname.x + (this.iname.width > this.itype.width ? (this.iname.width) : (this.itype.width));
                var _loc_3:* = this.l1.x + 7;
                this.isize.x = this.l1.x + 7;
                this.idimensions.x = _loc_3;
                this.deleteimage.visible = Boolean(this.target.value == "tuyitu");
                this.renameimage.visible = Boolean(this.target.value == "tuyitu");
                this.open.visible = true;
                this.ShowHideInfoOutside();
            }
            return;
        }// end function

        private function ShowHideInfoOutside() : void
        {
            if (this.isize.x + this.isize.width > this.width - 362 || this.idimensions.x + this.idimensions.width > this.width - 362)
            {
                this.l1.visible = false;
                this.isize.visible = false;
                this.idimensions.visible = false;
            }
            else
            {
                this.l1.visible = true;
                this.isize.visible = true;
                this.idimensions.visible = true;
            }
            return;
        }// end function

        public function ClearInfo() : void
        {
            this.l1.visible = false;
            this.open.visible = false;
            this.pwborder.visible = false;
            this.deleteimage.visible = false;
            this.renameimage.visible = false;
            this.idimensions.text = "";
            this.iname.text = "";
            this.isize.text = "";
            this.itype.text = "";
            return;
        }// end function

        public function OpenInAndStay(... args) : void
        {
            new OpenImageDialog(ed, this.imagelist.item.URL, this.imagelist.item.details.name, true, this.aslayer);
            return;
        }// end function

        public function OpenAndClose(... args) : void
        {
            ed.removeChild(this);
            ed.RemoveModal();
            new OpenImageDialog(ed, this.imagelist.item.URL, this.imagelist.item.details.name, true, this.aslayer);
            return;
        }// end function

        public function CloseClick(... args) : void
        {
            if (!AppState.TextInteraction)
            {
                this.Close();
            }
            return;
        }// end function

        public function Close() : void
        {
            if (ed != null)
            {
                ed.removeChild(this);
                ed.RemoveModal();
                ed.CheckToShowSplash();
            }
            return;
        }// end function

        private function GripMouseOver(event:MouseEvent) : void
        {
            ed.cursor.Set(ToolType.ResizeHeightWidth);
            return;
        }// end function

        private function GripMouseOut(event:MouseEvent) : void
        {
            ed.cursor.Set(ToolType.None);
            return;
        }// end function

        private function GripMouseMove(event:MouseEvent) : void
        {
            this.Resize(this.grip.x + 16, this.grip.y + 16, true);
            return;
        }// end function

        private function GripMouseDown(event:MouseEvent) : void
        {
            ed.cursor.freeze = true;
            this.grip.startDrag(false, new Rectangle(532, 402, 2000, 2000));
            stage.addEventListener(MouseEvent.MOUSE_MOVE, this.GripMouseMove, false, 0, true);
            stage.addEventListener(MouseEvent.MOUSE_UP, this.GripMouseUp, false, 0, true);
            return;
        }// end function

        private function GripMouseUp(event:MouseEvent) : void
        {
            this.grip.stopDrag();
            ed.cursor.freeze = false;
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, this.GripMouseMove, false);
            stage.removeEventListener(MouseEvent.MOUSE_UP, this.GripMouseUp, false);
            this.GripMouseMove(null);
            this.imagelist.Rearrange();
            if (event.target != this.grip)
            {
                ed.cursor.Set(ToolType.None);
            }
            return;
        }// end function

    }
}
